package com.itheima.doudizhu1;

import java.util.ArrayList;
import java.util.Collections;

public class pokerGame {

    //玩家
    static String p1Name = "张三";
    static String p2Name = "李四";
    static String p3Name = "王五";

    //创建集合存下每一张牌
    static ArrayList<String> list = new ArrayList<>();
    static ArrayList<String> list1 = new ArrayList<>();

    //静态代码块，用一次（准备一副牌就够了）
    static {
        //准备牌
        //将花色和号码分别放在两个集合，用于遍历都得到每一张牌
        String[] color = {"♠", "♥", "♣", "♦"};
        String[] number = {"3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A", "2"};
        String[] joker = {"小王", "大王"};

        //遍历
        for (String num : number) {
            for (String c : color) {
                //添加到集合
                list.add(c + num);
                list1.add(c + num);
            }
        }

        //再把大小王添加进去
        list.add(joker[0]);
        list.add(joker[1]);
        list1.add(joker[0]);
        list1.add(joker[1]);
        //观察
        System.out.println(list);
        System.out.println(list1);
    }

    public pokerGame() {

        //洗牌
        Collections.shuffle(list);
        System.out.println(list);

        //发牌
        //创建3个集合当成玩家用于存牌
        ArrayList<String> player1 = new ArrayList<>();
        ArrayList<String> player2 = new ArrayList<>();
        ArrayList<String> player3 = new ArrayList<>();

        ArrayList<String> player11 = new ArrayList<>();
        ArrayList<String> player21 = new ArrayList<>();
        ArrayList<String> player31 = new ArrayList<>();
        //再来一个集合放底牌
        ArrayList<String> diPai = new ArrayList<>();
        //遍历发牌
        //先放3张底牌
        for (int i = 0; i < 3; i++) {
            diPai.add(list.get(i));
        }
        //发完底牌开始给每个玩家发牌
        for (int i = 3; i < list.size() - 3; i += 3) {
            player1.add(list.get(i));
            player2.add(list.get(i + 1));
            player3.add(list.get(i + 2));
            //一次发完3个人之后i+3
        }

        //看牌
        System.out.print(p1Name + ":");
        for (String p1 : player1) {
            System.out.print(p1 + " ");
        }
        System.out.println();
        System.out.print(p2Name + ":");
        for (String p2 : player2) {
            System.out.print(p2 + " ");
        }
        System.out.println();
        System.out.print(p3Name + ":");
        for (String p3 : player3) {
            System.out.print(p3 + " ");
        }
        System.out.println();
        System.out.print("底牌:");
        for (String dp : diPai) {
            System.out.print(dp + " ");
        }

        //排序
        //遍历第二份没动的扑克，拿到每一张牌对比排序
        for (int i = 0; i < list1.size(); i++) {
            //拿到玩家手里每一张牌比较
            for (int j = 0; j < player1.size(); j++) {
                //判断
                if (list1.get(i).equals(player1.get(j))) {
                    //一样,直接添加
                    player11.add(player1.get(j));
                }
                if (list1.get(i).equals(player2.get(j))) {
                    //一样,直接添加
                    player21.add(player2.get(j));
                }
                if (list1.get(i).equals(player3.get(j))) {
                    //一样,直接添加
                    player31.add(player3.get(j));
                }

            }
        }
        System.out.println();
        System.out.println(player11);
        System.out.println(player21);
        System.out.println(player31);


    }

}
